/**
 * runtime 类的使用方法
 */
package edu.gzz;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author gzz
 *
 */
public class RuntimeTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// 
		Runtime rt = Runtime.getRuntime();

		System.out.println("available processors:" + rt.availableProcessors());
		System.out.println("max memory:" + rt.maxMemory());
		System.out.println("total memory:" + rt.totalMemory());
		System.out.println(rt.toString());

		open();
	}

	// 执行命令
	public static void open() {

		Runtime rn = Runtime.getRuntime();
		// String command = "ls / -l";
		String command = "dir";

		try {
			String s;
			Process p = rn.exec(command);
			BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));

			while ((s = br.readLine()) != null) {
				System.out.println(s);
			}

			// pr.waitFor();
			
		} catch (Exception e) {
			System.out.println("Error when execute " + command);
			e.printStackTrace();
			System.exit(1);
		}
	}

}
